package com.itheima.aop;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * AOP计算运行时间
 * @author GY
 * @version V1.0
 * @date 2025-01-17 12:13
 */
@Slf4j
@Aspect
@Component
@RequiredArgsConstructor
public class RecordTimeAccept {

@Pointcut("execution(* com.itheima.controller.*.*(..))")
    public void pc(){}

 //   @Around("pc()")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        if ("toString".equals(pjp.getSignature().getName())){
            return null;
        }
        long begin = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info("执行方法所在全类名 : {}",pjp.getSignature().getDeclaringTypeName());
        log.info("{}方法执行方法耗时 : {}",pjp.getSignature().getName(),(end-begin));
        return result;
    }
}


